package com.ruoyi.deeplearn.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.deeplearn.component.PublishTaskLayerProcess;
import com.ruoyi.deeplearn.vo.PublishTaskLayerVo;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.deeplearn.domain.DeepMarkTaskLayer;
import com.ruoyi.deeplearn.service.IDeepMarkTaskLayerService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 标注任务图层Controller
 *
 * @author rww
 * @date 2024-09-11
 */
@RestController
@RequestMapping("/deeplearn/taskLayer")
public class DeepMarkTaskLayerController extends BaseController
{
    @Autowired
    private IDeepMarkTaskLayerService deepMarkTaskLayerService;
    @Autowired
    private PublishTaskLayerProcess publishTaskLayerProcess;
    /**
     * 查询标注任务图层列表
     */
    @PreAuthorize("@ss.hasPermi('deeplearn:taskLayer:list')")
    @GetMapping("/list")
    public TableDataInfo list(DeepMarkTaskLayer deepMarkTaskLayer)
    {
        startPage();
        List<DeepMarkTaskLayer> list = deepMarkTaskLayerService.selectDeepMarkTaskLayerList(deepMarkTaskLayer);
        return getDataTable(list);
    }

    /**
     * 导出标注任务图层列表
     */
    @PreAuthorize("@ss.hasPermi('deeplearn:taskLayer:export')")
    @Log(title = "标注任务图层", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DeepMarkTaskLayer deepMarkTaskLayer)
    {
        List<DeepMarkTaskLayer> list = deepMarkTaskLayerService.selectDeepMarkTaskLayerList(deepMarkTaskLayer);
        ExcelUtil<DeepMarkTaskLayer> util = new ExcelUtil<DeepMarkTaskLayer>(DeepMarkTaskLayer.class);
        util.exportExcel(response, list, "标注任务图层数据");
    }

    /**
     * 获取标注任务图层详细信息
     */
    @PreAuthorize("@ss.hasPermi('deeplearn:taskLayer:query')")
    @GetMapping(value = "/{layerId}")
    public AjaxResult getInfo(@PathVariable("layerId") Long layerId)
    {
        return success(deepMarkTaskLayerService.selectDeepMarkTaskLayerByLayerId(layerId));
    }

    /**
     * 新增标注任务图层
     */
    @PreAuthorize("@ss.hasPermi('deeplearn:taskLayer:add')")
    @Log(title = "标注任务图层", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DeepMarkTaskLayer deepMarkTaskLayer)
    {
        return toAjax(deepMarkTaskLayerService.insertDeepMarkTaskLayer(deepMarkTaskLayer));
    }

    /**
     * 修改标注任务图层
     */
    @PreAuthorize("@ss.hasPermi('deeplearn:taskLayer:edit')")
    @Log(title = "标注任务图层", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DeepMarkTaskLayer deepMarkTaskLayer)
    {
        return toAjax(deepMarkTaskLayerService.updateDeepMarkTaskLayer(deepMarkTaskLayer));
    }

    /**
     * 删除标注任务图层
     */
    @PreAuthorize("@ss.hasPermi('deeplearn:taskLayer:remove')")
    @Log(title = "标注任务图层", businessType = BusinessType.DELETE)
	@DeleteMapping("/{layerIds}")
    public AjaxResult remove(@PathVariable Long[] layerIds)
    {
        return toAjax(deepMarkTaskLayerService.deleteDeepMarkTaskLayerByLayerIds(layerIds));
    }
    ///////////////////////////////////////
    //rasterTaskPublish
    @PostMapping("/rasterTaskPublish")
    public AjaxResult rasterTaskPublish(
            @RequestBody PublishTaskLayerVo publishTaskLayerVo, HttpServletResponse response)
    {
        publishTaskLayerProcess.sendPublishLayerMessage(publishTaskLayerVo);
        return AjaxResult.success("操作成功");
    }
}
